import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);
//创建并暴露出vuex的实例
export default new Vuex.Store({
    state: {//存储
        authorization: ''
    },
    getters: {//类似vue的computed
        getAuthorization: (state) => {
            return state.authorization;
        }
    },
    mutations: {//操作
        Authorization(state, authorization) {
            state.authorization = authorization;
        }
    },
    actions: {//官方推荐在actions中提交mutation再去修改状态值,可以包含任意异步操作
        setAuthorization(cxt,authorization) {
            return cxt.commit('Authorization',authorization)
        }
    }
})
